//
//  StatementFilterView.swift
//  ZNZXSuperMarket
//
//  Created by 四川中农 on 2018/8/6.
//  Copyright © 2018年 四川中农. All rights reserved.
//

import UIKit

class StatementFilterView: UIView {
    
    var titleArray = [String]()
    
    var seleClosure:BackStringValue!
    
    init(frame: CGRect,titleArray:[String]) {
        super.init(frame: frame)
        self.titleArray = titleArray
        let shadowLayer = CALayer.init()
        shadowLayer.frame = CGRect.init(x: 0, y: 0, width: self.width, height: 109.5)
        shadowLayer.cornerRadius = 20
        shadowLayer.backgroundColor = UIColor.white.cgColor
        shadowLayer.shadowColor = UIColor.init(hexColor: "#000000").cgColor
        shadowLayer.shadowOffset = CGSize.init(width: 0, height: 10)
        shadowLayer.shadowRadius = 5
        shadowLayer.shadowOpacity = 0.08
        self.layer.addSublayer(shadowLayer)
        
        
        self.initContent()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func initContent(){
        let bgView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: self.width, height: 109.5))
        bgView.corner(byRoundingCorners: [.bottomLeft,.bottomRight], radii: 20)
        bgView.backgroundColor = UIColor.nav_color
        self.addSubview(bgView)
        for i in 0 ..< 2{
            let btn = UIButton.init(type: .custom)
            btn.frame = CGRect.init(x: 0, y: CGFloat(i) * 55, width: UIScreen.ScreenWidth, height: 54.5)
            btn.setTitle(titleArray[i], for: .normal)
            btn.setTitleColor(UIColor.init(hexColor: "#1a1a1a"), for: .normal)
            btn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
            btn.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
            btn.tag = 100 + i
            bgView.addSubview(btn)
            
            if i == 1 {
                break
            }
            let viewLine = UIView.init(frame: CGRect.init(x: 12, y: 55, width: UIScreen.ScreenWidth - 24, height: 0.5))
            viewLine.backgroundColor = UIColor.backgroundColor
            bgView.addSubview(viewLine)
        }
    }
    
    @objc func btnClick(sender:UIButton){
        
        switch sender.titleLabel?.text {
        case "自定义统计":
            self.seleClosure("自定义统计")
            print("自定义统计")
        case "导出数据报表":
            print("导出数据报表")
            self.seleClosure("导出数据报表")
        default:
            break
        }
    }
    
}

